import QtQuick 1.0
import "/usr/share/libsocmdc/kdeadmouseutils-build-desktop"
Item {
  property string nom
  property string url
  signal allFinished()
  id:mainItem
  ShellInvoker {
    id : shellWget
    property bool startedVlc : false;
    onFinished : {
      console.log('##>:onFinished ');
      mainItem.allFinished();
    }
    
    onOutputLineChanged : {
	//console.log('#wget#>: ' + outputLine);
	if(startedVlc){return;}
	
	var pattern = / ([0-9]+)%/;
	var avance = pattern.exec(outputLine);
	var prcent = avance[1];
	console.log('avance<'+ prcent +'>');
	if(prcent>0){
	  startedVlc=true;
	  shellVlc.shellAction('vlc',['--avi-index','2',nom]);
	}
    }
    
    onLaunched : {
      
      vlcTimer.start();
      //shellVlc.shellAction('vlc',['--avi-index','2',nom]);
    }
    
  }
  
  ShellInvoker {
    id : shellVlc
    onFinished : {
      console.log('##>:onFinished ');
      shellWget.kill();
    }
    
    onOutputLineChanged : {
	console.log('#vlc#>: ' + outputLine);
    }
  }
  
  /*Timer {
	 id:vlcTimer
         interval: 1000
         running: false
         repeat: false
         onTriggered: {
	   shellVlc.shellAction('vlc',['--avi-index','2',nom]);
	 }
  }*/
  function playMedia(){
   shellWget.startedVlc=false;
   shellWget.shellAction('wget',['--progress=dot','--no-check-certificate','-c','-O',nom,url]); 
  }
  
  function kill() {
    shellVlc.kill();
  }
    
}
